package com.lwy.qiuchao.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.lwy.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lwy.qiuchao.ware.entity.SkuInfoEntity;
import com.lwy.qiuchao.ware.service.SkuInfoService;
import com.lwy.common.utils.PageUtils;


/**
 * 
 *
 * @author lwy
 * @email ${email}
 * @date 2020-12-01 15:54:08
 */
@RestController
@RequestMapping("ware/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     *
     * 通过skuid查询包括brandname的信息
     * */
    @RequestMapping("/skuinfo/{skuId}")
    public R skuinfobyid(@PathVariable("skuId")Long skuId){
        R r = skuInfoService.getinfo(skuId);
        return r;
    }
    /**
     * 删除商品的指定数目
     *
     * */
    @RequestMapping("/delete/{skuId}/{skuCount}")
    public R deleteNumbyskuid(@PathVariable("skuId")Long skuId,
                       @PathVariable("skuCount")Integer skuCount){
        R r = skuInfoService.deleteNumbyskuid(skuId,skuCount);
        return r;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = skuInfoService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/skusinfo")
    public R info(@RequestParam List<Long> skuids){
        List<SkuInfoEntity> list = skuInfoService.getList(skuids);

        return R.ok().put("list", list);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    public R info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);
        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
